#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int t;
  cin >> t;
  while (t --) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i ++) cin >> a[i];
    vector<i64> dp(n);
    dp[0] = a[0];
    dp[1] = a[0] + a[1] - 1;
    for (int i = 2; i < n; i ++) {
      dp[i] = min(dp[i - 1] + a[i] - 1,
                  dp[i - 2] + a[i - 1] + max(a[i] - i, 0));
    }
    debug(dp);
    cout << dp[n - 1] << '\n';
  }
}